import React ,{Component}from 'react'
import memoryUntils from '../../untils/memoryuntils'
import { Redirect ,Switch, Route} from 'react-router-dom';
import './index.scss'
import { Layout } from 'antd';
import Navleft from '../../component/Navleft/Navleft'
import Header from '../../component/Header/header'
import Footer from '../../component/Footer/footer'
import Home from '../home/home'
import Category from '../category/category'
import Role from '../role/role'
import User from '../user/user'
import Bar from '../echarts/bar'
import Line from'../echarts/line'
import Product from '../product/product'
import Pie from '../echarts/pie'
const {   Sider, Content } = Layout;

class Admin extends Component {
    constructor(props) {
        super(props);
        this.state = { 
            user:''
        };
    }
    

render(){
    const user =memoryUntils.user;
    // console.log("user:"+user)
    // 如果内存中没有user值，则返回登陆xs

    if(!user||user._id){
        // 自动跳到登陆界面
        return<Redirect to='/login'/>

    }
    return(
        <div className="adminstyle">
    <Layout  className="layout1">
      <Sider>
          <Navleft/>
          </Sider>
      <Layout className="layout2">
        <Header/>
        <Content style={{}} className="content">
            {/* 路由的基本使用在admin直接使用，并在Navleft中使用NAvlink跳转，后期优化可以封装路由 */}
            <Switch>
                <Route path='/home' component={Home} />
                <Route path='/user' component={User}/>
                <Route path='/product' component={Product}/>
                <Route path='/role' component={Role}/>
                <Route path='/echarts/bar' component={Bar}/>
                <Route path='/echarts/line' component={Line}/>
                <Route path='/echarts/pie' component={Pie}/>
                <Route path='/category' component={Category}/>
                {/* <Route path='/'  /> */}
                <Redirect to='/home'/>
            </Switch>

        </Content>
        <Footer/>
      </Layout>
    </Layout>
    </div>
             )
}
}
export default Admin;